const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show:false,
    coupon: [],
    conpon_num:0,
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    app.isLogin(function () {
      that.getApi(); 
    });
  },
  /**
   * 读取我的订单
   */
  getApi: function () {
    let that = this;
    let checked = false;
    app.api().Get("api/v1/allwin-coupon-manageStoreCoupon", function (result) {
      that.setData({
        coupon: result.data,
        conpon_num: app.util().count(result.data),
        skeleton: false,
      });
    })
  },
  //单个优惠券信息
  userCoupon: function (coupon_id) {
    let that = this;
    app.api().Get('api/v1/allwin-coupon-getcoupon', {'coupon_id': coupon_id }, function (res) {
      that.setData({
        coupon_info: res.data
      })
    })
  },
  /**
   * 规则弹窗
   */
  togglePopup(event) {
    let that = this;
    var show = that.data.show;
    this.setData({
      show: !show,
    });
    var id = event.currentTarget.dataset.id;
    if (!app.util().isNull(id)) {
      that.userCoupon(id);
    }
  },
  /**
   * 修改或创建赠品
   */
  editConpon: function (e) {
    var id = parseInt(e.currentTarget.id);
    if (id > 0){
      this.setData({
        show: false,
      });
      wx.navigateTo({
        url: 'couponedit?id=' + id
      })
    }else{
      wx.navigateTo({
        url: 'couponedit'
      })
    }
  }
})